import { LocationInfo } from '#/entity.ts';
import { create } from 'zustand';

interface LocationStore {
  locationData: LocationInfo[];
  currentIndex: number;
  tableIndex?: number;
  actions: {
    setLocationData: (data: LocationInfo[]) => void;
    setCurrentIndex: (index: number) => void;
    setTableIndex: (index?: number) => void;
  };
}

const locationStore = create<LocationStore>((set) => ({
  locationData: [],
  currentIndex: -1,
  tableIndex: undefined,
  actions: {
    setLocationData: (data) => set({ locationData: data }),
    setCurrentIndex: (index) => set({ currentIndex: index }),
    setTableIndex: (index) => set({ tableIndex: index }),
  },
}));

export const useLocationData = () => locationStore((state) => state.locationData);
export const useCurrentIndex = () => locationStore((state) => state.currentIndex);
export const useTableIndex = () => locationStore((state) => state.tableIndex);
export const useSetLocationData = () => locationStore((state) => state.actions.setLocationData);
export const useSetCurrentIndex = () => locationStore((state) => state.actions.setCurrentIndex);
export const useSetTableIndex = () => locationStore((state) => state.actions.setTableIndex);

export default locationStore;
